package cinema.ELTEcinema_ejb.Dao;

import javax.ejb.Stateless;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;

import cinema.ELTEcinema_ejb.Entity.User;

@SuppressWarnings("serial")
@Stateless
public class UserDAO extends AbstractDAO<User>{

	public UserDAO() {
		super(User.class);
	}

	public User validateUser(String uname, String password) {
		try{
			return em.createQuery("select u from User u where u.username = :uname and u.password = :password", User.class)
			.setParameter("uname", uname)
			.setParameter("password", password)
			.getSingleResult();
		}
		catch(NoResultException e){
			return null;
		}
		catch(NonUniqueResultException e){
			return null;
		}
	}
}